﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BL;
using BO;

namespace AnimalFarm.Field_Building_manage
{
    public partial class AddTheHerd : Form
    {
        public AddTheHerd()
        {
            InitializeComponent();
            loadField();
        }

        private void loadField()
        {
            B_Field bf = B_Field.CreateInstance();
            DataTable dTable = bf.GetAllField();
            if (dTable != null)
            {
                ddlField.DataSource = dTable;
                ddlField.DisplayMember = "FieldName";
                ddlField.ValueMember = "FieldID";
            }
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            string herdName = txtHerdName.Text;
            int fieldID = int.Parse(ddlField.SelectedValue.ToString());

            Herd_Info hInfo = new Herd_Info();
            B_Herd bH = B_Herd.CreateInstance();

            if (herdName != null && fieldID>0)
            {
                hInfo.HerdName = herdName;
                hInfo.FieldID = fieldID;

                bool isEffected = bH.CreateOneHerd(hInfo);
                if (isEffected == true)
                {
                    MessageBox.Show("Create a new herd type successfully!", "Creating successuflly", MessageBoxButtons.OK);
                    txtHerdName.Text = "";
                    txtHerdName.Focus();
                }
                else
                {
                    MessageBox.Show("Cannot create a new herd type successfully!", "Missing Data", MessageBoxButtons.OK);
                    txtHerdName.Focus();
                }
            }
        }
    }
}
